package com.os.serviceimpl;

import java.util.List;

import com.os.dao.StoreDaoH;
import com.os.daoimpl.StoreDaoImplH;
import com.os.model.StoreH;
import com.os.service.LoadStoreServiceH;

import net.sf.json.JSONObject;

public class LoadStoreServiceImplH implements LoadStoreServiceH{

	StoreDaoH sdao = new StoreDaoImplH();
	
	@Override
	public JSONObject loadStoresH(int page, int rows) {
		JSONObject jo = new JSONObject();
		int total = sdao.getAllStoresH();
		if (total != 0) {
			List<StoreH> stores = sdao.getLoadStoresH(page, rows);
			jo.put("total", total);
			jo.put("rows", stores);
		}else{
			List<StoreH> foods = sdao.getAllFoodsH();
			boolean falg = sdao.setStoresH(foods);
			if (falg) {
				List<StoreH> stores = sdao.getLoadStoresH(page, rows);
				total = sdao.getAllStoresH();
				jo.put("total", total);
				jo.put("rows", stores);
			}
		}
		return jo;
	}

}
